﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Depo
{
    public partial class Bilanco2 : XForm
    {
        string tip;
        public Bilanco2(string _tip)
        {
            InitializeComponent();
            tip = _tip;
            this.Text = "Bilanço";  // +tip;
            cmbTuru.EditValue = tip;
        }

        private void Bilanco2_Load(object sender, EventArgs e)
        {
            deGun.EditValueChanged += deGun_EditValueChanged;
            gridView1.RowCellStyle += gridView1_RowCellStyle;

            cmbTuru.EditValueChanged += cmbTuru_EditValueChanged;
            deGun.EditValue = DateTime.Today;
        }

        void cmbTuru_EditValueChanged(object sender, EventArgs e)
        {
            tip = cmbTuru.EditValue.ToStr();
            deGun_EditValueChanged(null, null);
        }

        private void Rfrsh()
        {
            switch (tip)
            {
                case "Tela":
                    gridView1.FormatAsNumber(1, "ToplamIdle", "ToplamAyrilmis", "MusteriTelasi", "ToplamQty", "ToplamTutar");
                    gridView1.FormatAsNumber(0, "TopAdedi");
                    gridView1.FormatAsNumber(3, "OrtTlFiyat");
                    gridView1.AddSummary("ToplamIdle", "ToplamAyrilmis", "MusteriTelasi", "ToplamQty", "ToplamTutar", "TopAdedi");
                    break;

                case "Kumas":
                    gridView1.FormatAsNumber(1, "ToplamIdle", "ToplamAyrilmis", "MusteriKumasi", "ToplamQty", "ToplamTutar");
                    gridView1.FormatAsNumber(0, "TopAdedi");
                    gridView1.FormatAsNumber(3, "OrtTlFiyat");
                    gridView1.FormatAsPercentage("FiyatiOlan");
                    gridView1.YanYanaGetir("ToplamTutar:FiyatiOlan");
                    gridView1.AddSummary("ToplamIdle", "ToplamAyrilmis", "MusteriKumasi", "ToplamQty", "ToplamTutar", "TopAdedi");
                    break;

                case "Aksesuar":
                    gridView1.FormatAsNumber(0, "AtilQty", "FaalQty", "ToplamQty", "ToplamTutar");
                    gridView1.FormatAsNumber(4, "OrtTlFiyat");
                    gridView1.AddSummary("AtilQty", "FaalQty", "ToplamQty", "ToplamTutar");
                    break;

                case "Koli":
                    gridView1.FormatAsNumber(0, "ToplamQty", "ToplamTutar");
                    gridView1.FormatAsNumber(4, "OrtTlFiyat");
                    gridView1.AddSummary("ToplamQty", "ToplamTutar");
                    break;
            }

            gridView1.BestFitColumns();
        }

        void deGun_EditValueChanged(object sender, EventArgs e)
        {
            if (deGun.EditValue.ToDate() < new DateTime(2016, 6, 1))
            {
                Notify("1 Haziran 2016'dan eski bilançolar sistemde kayıtlı değil.");
                deGun.EditValue = DateTime.Today;
            }
            else
            {
                gridView1.Init("GetBilanco3" + tip, deGun.EditValue.ToDate());
                gridView1.AddColumn("ToplamTutar", typeof(decimal), "OrtTlFiyat*ToplamQty");
                Rfrsh();

            }
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName.Contains("ToplamTutar"))
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
            else if (e.Column.FieldName.Contains("Equiv"))
                e.Appearance.ForeColor = Color.BlueViolet;
        }


    }
}
